#pragma once

#include <zenilib.h>

#include "PlayState.h"
#include "LevelEditor.h"
#include "Instructions.h"

using namespace Zeni;

class TitleState : public Zeni::Gamestate_Base
{
	public:
		TitleState();
		~TitleState();
	  
	private:
		void on_key(const SDL_KeyboardEvent &event) {
			m_play_button.on_event(event);
			m_instruct_button.on_event(event);
			m_editor_button.on_event(event);
			m_quit_button.on_event(event);
		  }

		  void on_mouse_motion(const SDL_MouseMotionEvent &event) {
			m_play_button.on_event(event);
			m_instruct_button.on_event(event);
			m_editor_button.on_event(event);
			m_quit_button.on_event(event);
		  }

		  void on_mouse_button(const SDL_MouseButtonEvent &event) {
			m_play_button.on_event(event);
			m_instruct_button.on_event(event);
			m_editor_button.on_event(event);
			m_quit_button.on_event(event);
		  }

		  void render();
		
		  class Play_Button : public Text_Button {
		  public:
			Play_Button::Play_Button()
			  : Text_Button(Point2f(50.0f, 330.0f), Point2f(200.0f, 380.0f),
							Color(),
							"titleButton",
							"Play",
							Color(1.0f, 0.0f, 0.0f, 0.0f))
			{
			}

			void on_hover(){
				m_bg = Widget_Rectangle_Color(get_upper_left(), get_lower_right(), get_Colors()["red"]);
			  }

			  void on_unhover(){
				m_bg = Widget_Rectangle_Color(get_upper_left(), get_lower_right(), get_Colors()["white"]);
			  }

			void on_accept() {
			  get_Game().push_state(new PlayState());
			}
		} m_play_button;

		class Instructions_Button : public Text_Button {
		  public:
			Instructions_Button::Instructions_Button()
			  : Text_Button(Point2f(50.0f, 400.0f), Point2f(200.0f, 450.0f),
							Color(),
							"titleButton",
							"Instructions",
							Color(1.0f, 0.0f, 0.0f, 0.0f))
			{
			}

			void on_hover(){
				m_bg = Widget_Rectangle_Color(get_upper_left(), get_lower_right(), get_Colors()["red"]);
			  }

			  void on_unhover(){
				m_bg = Widget_Rectangle_Color(get_upper_left(), get_lower_right(), get_Colors()["white"]);
			  }

			void on_accept() {
				get_Game().push_state(new Instructions());
			}
		  } m_instruct_button;

		class Editor_Button : public Text_Button {
		  public:
			Editor_Button::Editor_Button()
			  : Text_Button(Point2f(50.0f, 470.0f), Point2f(200.0f, 520.0f),
							Color(),
							"titleButton",
							"Level Editor",
							Color(1.0f, 0.0f, 0.0f, 0.0f))
			{
			}

			void on_hover(){
				m_bg = Widget_Rectangle_Color(get_upper_left(), get_lower_right(), get_Colors()["red"]);
			  }

			  void on_unhover(){
				m_bg = Widget_Rectangle_Color(get_upper_left(), get_lower_right(), get_Colors()["white"]);
			  }

			void on_accept() {
				get_Game().push_state(new LevelEditor(1));
			}
		  } m_editor_button;

		class Quit_Button : public Text_Button {
		  public:
			Quit_Button::Quit_Button()
			  : Text_Button(Point2f(50.0f, 540.0f), Point2f(200.0f, 590.0f),
							Color(),
							"titleButton",
							"Quit",
							Color(1.0f, 0.0f, 0.0f, 0.0f))
			{
			}

			void on_hover(){
				m_bg = Widget_Rectangle_Color(get_upper_left(), get_lower_right(), get_Colors()["red"]);
			  }

			  void on_unhover(){
				m_bg = Widget_Rectangle_Color(get_upper_left(), get_lower_right(), get_Colors()["white"]);
			  }

			void on_accept() {
			  throw Quit_Event();
			}
		  } m_quit_button;
  
};